/*
package com.noah.project;

import com.noah.project.global.Const;
import com.noah.project.global.JsonManager;
import com.noah.project.global.TokenManager;
import com.noah.project.model.Reply;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Component
public class TokenFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // TODO Auto-generated method stub
        System.out.println("------------test token filter init --------------");

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        // TODO Auto-generated method stub
        System.out.println("------------test token filter doFilter --------------");
        if (request instanceof HttpServletRequest) {
            HttpServletRequest req = (HttpServletRequest) request;
            String token = req.getHeader("token");
            System.out.println("token = " + token);
            if (TokenManager.INSTANCE.checkToken(token)) {
                System.out.println("通过了");
            } else {
                Reply reply = new Reply();
                reply.setCode(Const.FAIL_TOKEN);
                reply.setMsg("Token失效");
                response.setCharacterEncoding("UTF-8");
                response.setContentType("text/html;charset=utf-8");
                response.getWriter().println( JsonManager.INSTANCE.toJson(reply));
                return;
            }
        }
        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {
        // TODO Auto-generated method stub
        System.out.println("------------test token filter destory--------------");
    }


}


*/
